﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using Microsoft.Reporting.WebForms;
using Ewts.Code;

namespace Ewts.RDLC
{
    public partial class OutStorageDisRDLC : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                string outid = "";
                string outStorNo = "";
                List<ReportParameter> parameterList = new List<ReportParameter>();
                if (Request["outid"] != null && Request["outid"].ToString().Trim() != "")
                {
                    outid = Request["outid"].ToString().Trim();
                    outStorNo = new DataLib.BLL.OutStorage().GetModel(int.Parse(outid)).outStorageNo;
                    //GetReportMultipleDataSourceFile
                }

                DataSet barCodeDS = new DataLib.BLL.BarCode().GetList("outstrorageid='" + outid + "'");
                DataLib.Model.LoadNum loadModel = new DataLib.Model.LoadNum();
                DataLib.Model.Cumtomer cusModel = new DataLib.Model.Cumtomer();
                if (barCodeDS != null && barCodeDS.Tables[0].Rows.Count > 0)
                {
                    loadModel = new DataLib.BLL.LoadNum().GetModel(int.Parse(barCodeDS.Tables[0].Rows[0]["loadnumid"].ToString()));
                    cusModel = new DataLib.BLL.Cumtomer().GetModel((int)loadModel.customerid);
                    for (int i = 0; i < barCodeDS.Tables[0].Rows.Count; i++)
                    {
                        string load = barCodeDS.Tables[0].Rows[i]["loadnumv"].ToString();
                        load = load.Substring(0, 3);
                        if (int.Parse(load) == 086)
                        {
                            barCodeDS.Tables[0].Rows[i]["loadnumv"] = loadModel.loadnum;
                        }

                        barCodeDS.Tables[0].Columns.Add("CustomerName");
                        barCodeDS.Tables[0].Rows[i]["CustomerName"] = cusModel.companyname;
                    }

                    parameterList.Add(new ReportParameter("Date", barCodeDS.Tables[0].Rows[0]["outstoragedate"].ToString()));
                }

                //参数数据
                parameterList.Add(new ReportParameter("OutStorageNo", outStorNo));
                parameterList.Add(new ReportParameter("Other", ""));

                //为列表绑定数据
                ReportDataSource rds = new ReportDataSource("DataSet1", barCodeDS.Tables[0]);
                ReportViewer1.LocalReport.DataSources.Clear();
                ReportViewer1.LocalReport.DataSources.Add(rds);
                new RDLCPrinter().FillRow(barCodeDS.Tables[0], 3, 25,25);//为列表添加空行
                ReportViewer1.LocalReport.SetParameters(parameterList);
                ReportViewer1.LocalReport.Refresh();

            }
        }
    }
}